<include file="Public:header" />
<script type="text/javascript" src="__PUBLIC__/style/js/TableFreeze.js"></script>
<script src="__PUBLIC__/style/js/plugins/nice-scroll/jquery.nicescroll.min.js" type="text/javascript"></script>
<!-- daterangepicker -->
<link href="__PUBLIC__/css/daterangepicker.css" rel="stylesheet">
<script src="__PUBLIC__/js/daterangepicker/daterangepicker.js"></script>
<!--jQuery导出插件-->
<script type="text/javascript" src="__PUBLIC__/js/table-export/jquery.base64.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/table-export/tableExport.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/table-export/jspdf/libs/sprintf.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/table-export/jspdf/jspdf.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/table-export/jspdf/libs/base64.js"></script>
<!--jQuery导出插件-->
<style>
	body{
		overflow-y: hidden;
	}
</style>
<script>
$(function(){
	<if condition = "$_GET['content_id'] eq '' || $_GET['content_id'] eq 1">
		$("#table_div").height(window.innerHeight-$("#table_div").offset().top-$("#tfoot_div").height()-30);
		$(window).resize(function(){
			$("#table_div").height(window.innerHeight-$("#table_div").offset().top-$("#tfoot_div").height()-30);
			$("#oDivL_tab_Test3").height($("#table_div").height()).width($("#oTableLH_tab_Test3").width());
			$("#oDivH_tab_Test3").height($("#oTableLH_tab_Test3").height()).width($("#table_div").width());
		});
		var scroll_width = 7;
		$(".nicescroll").niceScroll({
			cursorcolor: "#999",//#CC0071 光标颜色
		    cursoropacitymax: 0.4, //改变不透明度非常光标处于活动状态（scrollabar“可见”状态），范围从1到0
		    touchbehavior: false, //使光标拖动滚动像在台式电脑触摸设备
		    cursorwidth: scroll_width+"px", //像素光标的宽度
		    cursorborder: "0", //     游标边框css定义
		    cursorborderradius: "3px",//以像素为光标边界半径
		    autohidemode: false, //是否隐藏滚动条
		    zindex:100,
		    background:"#F3F3F5",//滚动条背景色
		});
		$("#tab_Test3").FrozenTable(2,0,1);
		$("#oDivL_tab_Test3").height($("#table_div").height()).width($("#oTableLH_tab_Test3").width());
		$("#oDivH_tab_Test3").height($("#oTableLH_tab_Test3").height()).width($("#table_div").width());
	</if>
});
</script>
<script src="__PUBLIC__/js/chart/highcharts.js"></script>
<script src="__PUBLIC__/js/chart/modules/exporting.js"></script>
<div class="wrapper wrapper-content">
	<div class="row">
		<div class="col-lg-12">
			<include file="Public:alert" />
			<div class="ibox float-e-margins">
				<include file="Public:analytics_left" />
				<input type="hidden" id="content_id" value="{$content_id}">
				<div class="col-lg-10">
					<div class="ibox-content" style="padding-bottom:10px;border-bottom: none;">
						<form id="" class="form-group" method="get" style="margin-bottom: 0px;">
							<div class="row" style="height: 45px;">
								<div class="col-lg-4">
									<div class="pull-left" >
										<span style="font-size: 18px;color: #000;">
											<?php
												switch($_GET['content_id']){
													case 1:$content_name = '员工项目进展分析';break;
													case 2:$content_name = '客戶自定义分析';break;
													default :$content_name = '客戶统计报表';break;
												}
												echo $content_name;
											?>
										</span>
									</div>
								</div>
								<div class="col-lg-5">
								</div>
								<div class="col-lg-3">
									<div class="pull-right" >
										<div class="pull-left" style="margin-right: 10px;">
											<if condition = "$_GET['content_id'] eq 2 || $_GET['content_id'] eq 3">
												<span id="i_type_zhu">
													<i class="fa fa-bar-chart"></i>
												</span>
												<span style="line-height: 40px;"><a style="color: #75899D;" title="点击切换为柱状图" href="javascript:void(0);" id="origin_type_zhu" rel="0">切换为柱状图</span>
											<else />
												<div class="checkbox checkbox-primary">
													<input name="user_type" id="user_type" type="checkbox" <if condition="$_GET['user_type'] eq ''">checked="true" value=""<else />value="1"</if> />
													<label for="user_type">仅显示销售岗数据</label>
												</div>
											</if>
										</div>
										<!-- <div class="pull-left" style="margin-left: 15px;line-height: 40px;">
											<span class="fa fa-download" style="color:#75899D;"></span>
											<a style="color: #75899D;" title="点击导出Excel表格" onClick ="$('#tab_Test3').tableExport({type: 'excel', escape: 'false'});">导出</a>
										</div> -->
									</div>
								</div>
							</div>
							<div class="row" >
								<input type="hidden" name="m" value="customer" />
								<input type="hidden" name="a" value="analytics" />
								<input type="hidden" name="content_id" value="<php>echo $content_id = $_GET['content_id'] ? intval($_GET['content_id']) : 1;</php>" />
								<div class="col-lg-12" >
									<if condition = "$_GET['content_id'] eq 2">
										<ul class="nav pull-left" style="margin:2px 0 0 0;">
											<li>
												<div class="input-group">
													<select class="form-control input-sm " style="min-width:165px;max-width: 165px;" name="field" >
														<option value="origin" <if condition="$field eq 'origin'">selected</if>>客户信息来源</option>
														<volist name="fields_array" id="vo">
															<if condition = "$vo['field'] neq 'origin'">
																<option value="{$vo['field']}" <if condition="$field eq $vo['field']">selected</if>>{$vo['field_name']}</option>
															</if>
														</volist>
													</select>
												</div>
											</li>
										</ul>
									</if>
									<ul class="nav pull-left" style="margin:2px 0 0 15px;">
										<li>
											<div class="input-group">
												<input type="text" name="between_date" id="reservation" class="form-control" style="width:300px;"/>
												<i class="glyphicon glyphicon-calendar fa fa-calendar" style="position: absolute;bottom: 10px;right: 24px;top: auto;cursor: pointer;"></i>
											</div>
										</li>
									</ul>
									<ul class="nav pull-left" style="margin:2px 0 0 15px;">
										<li>
											<div class="input-group">
												<select class="form-control input-sm " style="min-width:165px;max-width: 165px;" name="department" id="department" onchange="changeRole()">
													<option class="all" value="all">{:L('ALL')}</option>
													<volist name="departmentList" id="vo">
														<option value="{$vo.department_id}">{$vo.name}</option>
													</volist>
												</select>
											</div>
										</li>
									</ul>
									<ul class="nav pull-left" style="margin:2px 0 0 15px;">
										<li>
											<div class="input-group">
												<select class="form-control input-sm " style="min-width:165px;max-width: 165px;" name="role" id="role" onchange="changeCondition()">
													<option class="all" value="all">{:L('ALL')}</option>
													<volist name="roleList" id="vo">
														<option value="{$vo.role_id}" <if condition="$_GET['role'] eq $vo['role_id']">selected</if>>{$vo.role_name}-{$vo.user_name}</option>
													</volist>
												</select>
											</div>
										</li>
									</ul>
									<div class="pull-left" style="margin-left: 20px;">
										<button type="submit" id="analytics_search" class="btn btn-primary">{:L('SEARCH')}</button>
									</div>
								</div>
							</div>
						</form>
					</div>
					<div class="ibox-content" id="right_height" style="border-top: none;padding-top: 0px;">
						<if condition = "$_GET['content_id'] eq 1 || $_GET['content_id'] eq ''">
							<div id="content_1" class="th_content" style="position:relative;">
								<div id="table_div" class="nicescroll" style="left:0px;top:0px;">
									<table class="table table-hover table-striped table_thead_fixed table-bordered" id="tab_Test3" style="background:#fff;margin-bottom:0px;">
										<tbody>
                                        <tr class="tabTh">
											<td>员工姓名</td>
											<td style="min-width: 100px;">英文名</td>
											<td style="min-width: 80px;">部门</td>
											<td style="min-width: 80px;">项目名称</td>
											<td style="min-width: 80px;">所属客户</td>
											<td style="min-width: 80px;">项目类型</td>
											<td style="min-width: 80px;">CallList</td>
											<td style="min-width: 80px;">顾问面试</td>
											<td style="min-width: 80px;">推荐人才</td>
											<td style="min-width: 80px;">面试</td>
											<td style="min-width: 80px;">到场数</td>
											<td style="min-width: 80px;">面试通过</td>
											<td style="min-width: 80px;">Offer</td>
											<td style="min-width: 80px;">Offer掉</td>
											<td style="min-width: 80px;">入职</td>
											<td style="min-width: 80px;">过保</td>
											<!--<td>客户数</td>-->
											<!--<td>成交客户数</td>-->
											<!--<td>客户成交率</td>-->
											<!--<td>商机数</td>-->
											<!--<td>赢单商机数</td>-->
											<!--<td>商机赢单率</td>-->
											<!--<td>合同总金额(元)</td>-->
											<!--<td>平均合同金额(元)</td>-->
											<!--<td>回款金额(元)</td>-->
											<!--<td>未回款金额(元)</td>-->
											<!--<td>回款比例</td>-->
										</tr>
                                        <tr class="tabTh" style="background: #70B4E8;color: #fff;font-size: 13px;">
                                            <td>{:L('SUM_TO')}</td>
                                            <td style="min-width: 100px;color:#fff;"></td>
                                            <td style="min-width: 80px;color:#fff;">{$total_report['own_customer_count_total']}</td>
                                            <td style="color:#fff;">{$total_report['success_customer_count_total']}</td>
                                            <td style="min-width: 80px;color:#fff;">{$total_report['success_customer_rate_total']}%</td>
                                            <td style="min-width: 80px;color:#fff;">{$total_report['own_business_count_total']}</td>
                                            <td style="min-width: 80px;color:#fff;">{$total_report['success_business_count_total']}</td>
                                            <td style="min-width: 80px;color:#fff;">{$total_report['success_business_rate_total']}%</td>
                                            <td style="min-width: 80px;color:#fff;">{$total_report['contract_price_total']}</td>
                                            <td style="min-width: 80px;color:#fff;">{$total_report['contract_average_total']}</td>
                                            <td style="min-width: 80px;color:#fff;">{$total_report['receivingorder_price_total']}</td>
                                            <td style="min-width: 80px;color:#fff;">{$total_report['un_receivingorder_price_total']}</td>
                                            <td style="min-width: 80px;color:#fff;">{$total_report['receivingorder_rate_total']}%</td>
                                            <td style="min-width: 80px;">Offer掉</td>
                                            <td style="min-width: 80px;">入职</td>
                                            <td style="min-width: 80px;">过保</td>
                                        </tr>
										<volist name="reportList" id="vo">
										<tr>
											<td><a class="role_info" rel="{$vo.user.role_id}" href="javascript:void(0)">{$vo.user.user_name}</a></td>
											<td>{$vo['user']['number']}</td>
											<td><a href="{:U('customer/index')}&field=creator_role_id&search={$vo.user.role_id}&between_date={$between_date}">{$vo.own_customer_count}</a></td>
											<td><a href="{:U('customer/index')}&field=owner_role_id&search={$vo.user.role_id}&between_date={$between_date}">{$vo.success_customer_count}</a></td>
											<td>{$vo.success_customer_rate}%</td>
											<td>{$vo.own_business_count}</td>
											<td>{$vo.success_business_count}</td>
											<td>{$vo.success_business_rate}%</td>
											<td>{$vo.contract_price}</td>
											<td>{$vo.contract_average}</td>
											<td>{$vo.receivingorder_price}</td>
											<td>{$vo.un_receivingorder_price}</td>
											<td>{$vo.receivingorder_rate}%</td>
                                            <td style="min-width: 80px;">Offer掉</td>
                                            <td style="min-width: 80px;">入职</td>
                                            <td style="min-width: 80px;">过保</td>
										</tr>
										</volist>
                                        </tbody>
									</table>
								</div>
								<div id="tfoot_div" class="clearfix">
								</div>
							</div>
						</if>
						<if condition = "$_GET['content_id'] eq 2">
							<div id="content_2" class="th_content full-height-scroll">
								<div id="an_chart" class="col-lg-6" style="margin-left: 5px;">
									<div id="canvas_source" style="max-width:inherit;min-width:62%; height: 450px;margin: 0 auto">{:L('TEMPORARILY_NO_DATA')}</div>
									<div id="canvas_source_zhu" class="hidden" style="min-width: 500px; height: 500px;margin: 0 auto">{:L('TEMPORARILY_NO_DATA')}</div>
								</div>
								<div class="col-lg-5" style="margin-left: 5px;">
									<table class="table table-hover " style="margin-top: 80px;border:1px solid #ccc;background-color: #f9f9f9;">
										<tr style="background-color: #F4F4F4;">
											<td style="border-top: none;">{$field_name}</td>
											<td style="border-top: none;">个数</td>
											<td style="border-top: none;">占比</td>
										</tr>
										<volist name="field_count_list" id="vo">
											<tr>
												<td>{$vo['name']}</td>
												<td>{$vo['num']}</td>
												<td>{$vo['rate']}%</td>
											</tr>
										</volist>
									</table>
								</div>
							</div>
						</if>
						<div class="clearfix"></div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<div style="display: none;" id="dialog-role-info" title="{:L('EMPLOYEE_INFORMATION')}">
	<div class="spiner-example">
		<div class="sk-spinner sk-spinner-three-bounce">
			<div class="sk-bounce1"></div>
			<div class="sk-bounce2"></div>
			<div class="sk-bounce3"></div>
		</div>
	</div>
</div>
<script type="text/javascript">

	//时间插件
    $('#reservation').daterangepicker({
        startDate: '{$start_date}',
        endDate: '{$end_date}',
        //minDate: '01/01/2012',    //最小时间
        maxDate : moment(), //最大时间
        showDropdowns : true,
        showWeekNumbers : false, //是否显示第几周
        // timePicker : true, //是否显示小时和分钟
        // timePickerIncrement : 60, //时间的增量，单位为分钟
        timePicker12Hour : false, //是否使用12小时制来显示时间
        ranges : {
            //'最近1小时': [moment().subtract('hours',1), moment()],
            '今日': [moment().startOf('day'), moment()],
            '昨日': [moment().subtract('days', 1).startOf('day'), moment().subtract('days', 1).endOf('day')],
            '上月': [moment().subtract('days', '{$daterange[0][start_day]}'), moment().subtract('days', '{$daterange[0][end_day]}')],
            '本月': [moment().subtract('days', '{$daterange[1][start_day]}'), moment()],
            '上季度': [moment().subtract('days', '{$daterange[2][start_day]}'), moment().subtract('days', '{$daterange[2][end_day]}')],
            '本季度': [moment().subtract('days', '{$daterange[3][start_day]}'), moment()],
            '上一年': [moment().subtract('days', '{$daterange[4][start_day]}'), moment().subtract('days', '{$daterange[4][end_day]}')],
            '本年': [moment().subtract('days', '{$daterange[5][start_day]}'), moment()],
            // '最近7日': [moment().subtract('days', 6), moment()],
            // '最近30日': [moment().subtract('days', 29), moment()]
        },
        opens : 'right', //日期选择框的弹出位置
        buttonClasses : [ 'btn btn-default' ],
        applyClass : 'btn-small btn-primary blue',
        cancelClass : 'btn-small',
        separator : ' to ',
        locale : {
            applyLabel : '确定',
            cancelLabel : '取消',
            fromLabel : '起始时间',
            toLabel : '结束时间',
            customRangeLabel : '自定义',
            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
            monthNames: ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],
            firstDay : 1 ,
            format : 'YYYY-MM-DD', //控件中from和to 显示的日期格式
        },
        "alwaysShowCalendars": true,
        function(start, end, label) {
        	//回调
        	$('#reservation').val(start.format('YYYY-MM-DD HH:mm:ss') + ' - ' + end.format('YYYY-MM-DD HH:mm:ss'))
  			// console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
    	}
    });

	$("#dialog-role-info").dialog({
		autoOpen: false,
		modal: true,
		width: 600,
		maxHeight: 550,
		position: ["center",100]
	});
	$(".role_info").click(function(){
		$role_id = $(this).attr('rel');
		$('#dialog-role-info').dialog('open');
		$('#dialog-role-info').load('{:U("user/dialoginfo","id=")}'+$role_id);
	});
	$(function () {
		<if condition="$own_customer_count_total gt 0">
			var chart1; //客戶信息來源饼状图
			$('#canvas_source').highcharts({
				chart1: {
					plotBackgroundColor: null,
					plotBorderWidth: null,
					plotShadow: false
				},
				// title: {
				// 	text: '{:L('CUSTOMER_SOURCE_STATISTICS_SUM_TO',array($field['origin'],$total_report['own_customer_count']))}'
				// },
				title :{
					text : ''
				},
				tooltip: {
					pointFormat: '{series.name}: <b>{point.percentage:.2f}%</b>',
					percentageDecimals: 1
				},
				plotOptions: {
					pie: {
						allowPointSelect: true,
						cursor: 'pointer',
						dataLabels: {
							enabled: true,
							format: '<b>{point.name}</b>: {point.percentage:.2f} %',
		                    style: {
		                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
		                    }
						},
						showInLegend: true
					}
				},
				series: [{
					type: 'pie',
					name: '{$field_name}',
					data: [
						{$field_count}
					]
				}]
			});

			//var chart2; 客戶信息來源柱状图
		    $('#canvas_source_zhu').highcharts({
		        chart: {
		            type: 'column'
		        },
		        title: {
		            text: ''
		        },
		        subtitle: {
		            text: ''
		        },
		        xAxis: {
		            type: 'category',
		            labels: {
		                rotation: -45,
		                style: {
		                    fontSize: '13px',
		                    fontFamily: 'Verdana, sans-serif'
		                }
		            }
		        },
		        yAxis: {
		            min: 0,
		            title: {
		                text: '数量 (个)'
		            }
		        },
		        legend: {
		            enabled: false
		        },
		        tooltip: {
		            pointFormat: '客户总数: <b>{point.y:.1f} 个</b>'
		        },
		        series: [{
		            name: '总客户数',
		            data: [
		                {$field_count}
		            ],
		            dataLabels: {
		                enabled: true,
		                rotation: -90,
		                color: '#FFFFFF',
		                align: 'right',
		                format: '{point.y:.1f}', // one decimal
		                y: 10, // 10 pixels down from the top
		                style: {
		                    fontSize: '13px',
		                    fontFamily: 'Verdana, sans-serif'
		                }
		            }
		        }]
		    });
		</if>
	});

	$("#origin_type_zhu").click(function(){
		var rel = $(this).attr('rel');
		if(rel == '0'){
			$("#canvas_source_zhu").removeClass('hidden');
			$("#canvas_source").addClass('hidden');

			$(this).attr('rel',1);
			$(this).html('切换为饼状图');
			$('#i_type_zhu').html('<i class="fa fa-pie-chart"></i>');
		}else{
			$("#canvas_source_zhu").addClass('hidden');
			$("#canvas_source").removeClass('hidden');

			$(this).attr('rel',0);
			$(this).html('切换为柱状图');
			$('#i_type_zhu').html('<i class="fa fa-bar-chart"></i>');
		}
	});

	function changeRole(){
		department_id = $("#department option:selected").val();
		$.ajax({
			type:'get',
			url:'index.php?m=user&a=getrolebydepartment&department_id='+department_id,
			async:true,
			success:function(data){
				options = '<option value="all">{:L('ALL')}</option>';
				if(data.data != null){
					$.each(data.data, function(k, v){
						options += '<option value="'+v.role_id+'">'+v.role_name+"-"+v.user_name+'</option>';
					});
				}
				$("#role").html(options);
				<if condition="$_GET['role']">
				$("#role option[value='{$Think.get.role}']").prop("selected", true);
				</if>
			},
			dataType:'json'});
	}

	$("#user_type").click(function(){
		var user_type = $(this).is(':checked');
		var between_date = $('#reservation').val();
		if(user_type == true){
			window.location.href = "{:U('customer/analytics','content_id=1'.'&between_date=')}"+between_date;
		}else{
			window.location.href = "{:U('customer/analytics','&content_id=1'.'&between_date=')}"+between_date+'&user_type=1';
		}
	});

	<if condition="$_GET['department'] and $_GET['department'] neq 'all'">
	$("#department option[value='{$Think.get.department}']").prop("selected", true);
	changeRole();
	</if>
	<if condition="$_GET['department'] eq 'all'">
	$("#role option[value='{$Think.get.role}']").prop("selected", true);
	</if>
</script>
<include file="Public:footer" />
